package com.szq.ai.healthcare.config;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.pgvector.PgVectorEmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeEmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeServerlessIndexConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: szq
 * @description:
 * @date: 2025-05-28 15:16:26
 * @return
 */
@Configuration
public class EmbeddingStoreConfig {

    @Autowired
    private EmbeddingModel embeddingModel;

    @Bean
    public EmbeddingStore<TextSegment> embeddingStore() {
        //创建向量存储
        /*EmbeddingStore<TextSegment> embeddingStore = PineconeEmbeddingStore.builder()
                .apiKey("pcsk_4iECTc_LAS6iMZqiQzkUnRzQ6eKHne521ZgLNqmiQUukhEgZen26eJRAonyWrXws1FhEk1")
                .index("ai-index")
                .nameSpace("healthcare")
                .createIndex(PineconeServerlessIndexConfig.builder()
                        .cloud("AWS")
                        .region("us-east-1")
                        .dimension(embeddingModel.dimension())
                        .build())
                .build();*/
        //存储到pgsql中
        EmbeddingStore<TextSegment> embeddingStore = PgVectorEmbeddingStore.builder()
                .host("192.168.213.128")
                .port(15432)
                .database("ai_healthcare")
                .user("postgres")
                .password("postgres")
                .table("healthcare")
                .dimension(embeddingModel.dimension())
                .build();
        //存储到本地
        /*EmbeddingStore<TextSegment> embeddingStore = PgVectorEmbeddingStore.builder()
                .host("localhost")
                .port(5432)
                .database("ai_healthcare")
                .user("postgres")
                .password("123456")
                .table("healthcare")
                .dimension(embeddingModel.dimension())
                .build();*/
        return embeddingStore;
    }
}
